#include<stdio.h>
//#include<iostream>
//using namespace std;
#include "lua.hpp"
extern "C"
{
//#include"lua.h"
#include"lauxlib.h"
#include"lualib.h"
}

lua_State *GlobalL;
static int StackDump(lua_State *L)
{
	int top = lua_gettop(L);
	for(int i = 1; i <= top; i++)
	{
		int t = lua_type(L, i);
		switch(t)
		{
			case LUA_TSTRING:
				{
					printf("'%s'", lua_tostring(L, i));
					break;
				}
			case LUA_TBOOLEAN:
				{
					printf(lua_toboolean(L, i) ? "true" : "false");
					break;
				}
			case LUA_TNUMBER:
				{
					printf("%g", lua_tonumber(L, i));
					break;
				}
			default:
				{
					printf("%s", lua_typename(L, t));
					break;
				}
		}
		printf(" ");
	}
	printf("\n");
}

const luaL_Reg FunctionReg[] =
{
	{"StackDump", StackDump},
	{NULL, NULL},
};

int main()
{
	luaL_register(GlobalL, "CFunction", FunctionReg);
	return 0;
}
